using System;
using System.Collections.Generic;
using System.Dynamic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Net;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.OData;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using  server.status_db;
[Authorize]
public class JsqtqkhzController : ODataController
{
    private status_oneContext _db;
    public JsqtqkhzController(status_oneContext context)
    {
        _db = context;

    }
    private bool 教师其他情况汇总Exists(Guid key)
    {
        return _db.JS_B_教师其他情况汇总.Any(p => p.ID == key);
    }
    [HttpPut]
    public async Task<IActionResult> Put([FromODataUri] Guid key, [FromBody]JS_B_教师其他情况汇总 update)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }
        if (key != update.ID)
        {
            return BadRequest();
        }
        _db.Entry(update).State = EntityState.Modified;
        try
        {
            await _db.SaveChangesAsync();
        }
        catch (DbUpdateConcurrencyException)
        {
            if (!教师其他情况汇总Exists(key))
            {
                return NotFound();
            }
            else
            {
                throw;
            }
        }
        return Updated(update);
    }
    public async Task<IActionResult> Delete([FromODataUri] Guid key)
    {
        var mc = await _db.JS_B_教师其他情况汇总.FindAsync(key);
        if (mc == null)
        {
            return NotFound();
        }
        _db.JS_B_教师其他情况汇总.Remove(mc);
        await _db.SaveChangesAsync();
        return NoContent();
    }
     [HttpGet("/api/Jsqtqkhz/GetData")]
  public IActionResult GetData(String XXID, String CJPC, String query, string order, int limit, int skip, String viewMode)
  {
    //
    Console.WriteLine("query " + query);
    //

    var datas = _db.JS_B_教师其他情况汇总.Where("XXID == @0 and CJPC == @1 and (是否删除 ==0 or 是否删除 == null)", XXID, CJPC);
    if (viewMode == "是")
      datas = datas.Where("审核状态 ==\"通过\"");
    if (query != null)
      datas = datas.Where(query);

  
    dynamic temp = new ExpandoObject();
    temp.total = datas.Count();
    temp.values = datas.OrderBy(order).Skip(skip).Take(limit).ToArray();

    return this.Ok(temp);
  }
    [HttpPost]
    public async Task<IActionResult> Post([FromBody] JS_B_教师其他情况汇总 model)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }
        _db.JS_B_教师其他情况汇总.Add(model);
        await _db.SaveChangesAsync();

        return Created(model);
    }
    [EnableQuery]
    public IActionResult Get()
    {
        return Ok(_db.JS_B_教师其他情况汇总);
    }
    //
}